
    <!-- 导航 -->
  <include file="Public/header" />
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/lib/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/lib/ueditor/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/lib/ueditor/lang/zh-cn/zh-cn.js"></script>
 
      <div class="x12 border-bottom padding">
        <ul class="bread">
          <li><a href="__MODULE__/" class="icon-home"> 系统首页</a></li>
          <li><a href="__MODULE__/News">新闻管理</a></li>
          <li>编辑新闻</li>
        </ul>
      </div>
      <div class="x12 padding" >
        <form class="form-x form-block" action="#" method="post" >

          <div class="form-group x12">
            <div class="label"><label for="title">新闻标题*</label></div>
            <div class="field x5">
              <input type="text" class="input box-shadow-none radius-none" value="{$news.title}" name="title" size="50"  placeholder="新闻标题" />
            </div>
          </div>

          <div class="form-group x12">
            <div class="label"><label for="author">新闻作者</label></div>
            <div class="field x5">
              <input type="text" class="input box-shadow-none radius-none" value="{$news.author}" name="author" size="50"  placeholder="新闻作者" />
            </div>
          </div>
          <div class="form-group x12">
            <div class="label"><label for="username">新闻分类</label></div>
            <div class="field x2">
              <select class="input box-shadow-none radius-none" name="cid" >
                <volist name="lists" id="vo">
                  <option value="{$vo.id}" <if condition="$news['cid'] eq $vo['id'] ">selected</if>>{$vo.name}</option>
                  <volist name="vo.lower" id="rs" key="k">
                    <option value="{$rs.id}" <if condition="$news['cid'] eq $rs['id'] ">selected</if>>├──　　{$rs.name}</option>
                  </volist>
                </volist>
              </select>
            </div>
          </div>

          <div class="form-group x12">
            <div class="label"><label for="title">新闻简介</label></div>
            <div class="field x5">
              <textarea class="input box-shadow-none radius-none" name="desc" rows="5" cols="50" placeholder="新闻简介">{$news.desc}</textarea>
            </div>
          </div>

          <div class="form-group x12">
            <div class="label"><label for="content">新闻封面</label></div>
            <div class="field x12">

              <div class="input-group padding-little-top x8">
                <input type="text" class="input border-sub box-shadow-none radius-none" id="picture" name="img" value="{$news.img}" placeholder="" >
                <span class="addbtn">
                  <a href="javascript:void(0);" class="button input-file bg-sub" onclick="upImage();">+ 上传图片</a>
                </span>
              </div>

              <div class="x4 padding-little">
                <img id="preview" src="" width="34" height="34" class="radius-big" style="cursor:pointer" />
              </div>
              <script type="text/plain" id="upload_ue"></script>

            </div>
          </div>

          <div class="form-group x12">
            <div class="label"><label for="content">新闻内容</label></div>
            <div class="field x12">          
              <textarea type="text/plain" id="editor" style="width:100%;height:300px;">{$news.content}</textarea>

            </div>
          </div>

          <div class="form-group x12">
            <div class="label"><label for="username">排序</label></div>
            <div class="field x1">
              <input type="number" min="0" class="input box-shadow-none radius-none" name="sort" value="{$news.sort|default='0'}" datatype="*" />
            </div>
          </div>
			<div class="clearfix"></div>
          <div class="margin-big-top text-center bg padding">
             <button class="btn button bg-sub" type="button" onclick="add_news({$news.id})"> 确 定 发 布</button> 
        </div>
      </form>

   
      </div>
    </div>
    <!-- 底部 -->
    <include file="foot" />
  </div>



<script type="text/javascript">
    //实例化编辑器
    var ue = UE.getEditor('editor',{
	serverUrl:'{:U("Admin/Upload/index")}',
	toolbars:[[
	'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain','forecolor', 'backcolor', 
	'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', 'touppercase', 'tolowercase', 
	'link', 'unlink','imagenone', 'imageleft', 'imageright', 'imagecenter',
	'simpleupload', 'insertimage', 'map','fullscreen'
	]]
});

    //上传独立使用
        var _editor = UE.getEditor('upload_ue',{
    	serverUrl:'{:U("Admin/Upload/index")}',
    	toolbars:[[
    	'insertimage', 
    	]]
    });
        _editor.ready(function () {
			
            
            _editor.hide();

            _editor.addListener('beforeInsertImage', function (t, arg) {     //侦听图片上传
                $("#picture").attr("value", arg[0].src);                      //将地址赋值给相应的input
                $("#preview").attr("src", arg[0].src);
            })
        });
        function upImage() {
            var myImage = _editor.getDialog("insertimage");
            myImage.open();
        }
        function upFiles() {
            var myFiles = _editor.getDialog("attachment");
            myFiles.open();
        }


function add_news(id){


	var title=$("input[name='title']");
	var cid=$("select[name='cid']").val();
	var desc=$("textarea[name='desc']").val();
	var img=$("input[name='img']").val();

	var author=$("input[name='author']").val();
	 content=ue.getContent();
	var sort=$("input[name='sort']").val();
	
	if(title.val().length < 1){
		layer.tips('新闻标题不能为空', title);
		title.focus()
		return false
	}
	if(content.length < 1){
		layer.msg('内容不能为空', {
				offset: 200,
				shift: 2
			});
		return false
	}
	
	 $.post("__MODULE__/News/news_edit",{
		title:title.val(),
		cid:cid,
		desc:desc,
		img:img,
		author:author,
		id:id,
		content:content,
		sort:sort,
	},function(ret){
		if(ret.status==1){
			layer.msg(ret.info, {
						offset: 200,
						shift: 2
			});
			window.location.href=ret.url
		}else{
			layer.msg(ret.info, {
						offset: 200,
						shift: 2
			});
		}

	})
	
}

</script>





</body>
</html>